package com.juezhuo.ocrs.website.erp.web.controller;

import net.sf.json.JSONArray;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: homjarel
 * Date: 2011-12-22
 * Time: 13:23:38
 * To change this template use File | Settings | File Templates.
 */

@Controller
@RequestMapping("/category")
public class CategoryDisController {


    @RequestMapping("/categoryDis")
	public ModelAndView addUser() {
        ModelAndView view = new ModelAndView("/category/categoryDis");
        return view;
	}

     @RequestMapping(value = "/queryTree")
    public void queryJson(Model view, HttpServletRequest request, HttpServletResponse response) throws IOException {

       List<String> resourceTreeInfo = new ArrayList<String>();

           String temp =  "{id:1,pid:-1, name:'1',open:true}";
           String temp1 =  "{id:2,pid:1, name:'2',open:true}";
           String temp2 =  "{id:3,pid:1, name:'3',open:true}";
           String temp3 =  "{id:4,pid:2, name:'4',open:true}";
           String temp4 =  "{id:5,pid:2, name:'5',open:true}";
           String temp5 =  "{id:6,pid:3, name:'6',open:true}";
           String temp6 =  "{id:7,pid:3, name:'7',open:true}";
           resourceTreeInfo.add(temp);
           resourceTreeInfo.add(temp1);
           resourceTreeInfo.add(temp2);
           resourceTreeInfo.add(temp3);
           resourceTreeInfo.add(temp4);
           resourceTreeInfo.add(temp5);
           resourceTreeInfo.add(temp6);

        response.setContentType("text/html;charset=UTF-8");
        response.getWriter().print(JSONArray.fromObject(resourceTreeInfo).toString());

    }

}